package com.ruoyi.cms.controller;

import com.ruoyi.cms.domain.CmsFeedback;
import com.ruoyi.cms.service.ICmsFeedbackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 在线留言反馈Controller
 *
 * @author houyong
 * @date 2025-11-18
 */
@RestController
@RequestMapping("cms/manager/feedback")
public class CmsFeedbackController extends BaseController {
    @Autowired
    private ICmsFeedbackService cmsFeedbackService;

    /**
     * 查询在线留言反馈列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmsFeedback cmsFeedback) {
        startPage();
        List<CmsFeedback> list = cmsFeedbackService.selectCmsFeedbackList(cmsFeedback);
        return getDataTable(list);
    }

    /**
     * 获取在线留言反馈详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(cmsFeedbackService.selectCmsFeedbackById(id));
    }

    /**
     * 删除在线留言反馈
     */
    @Log(title = "删除在线留言反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        String userName = SecurityUtils.getUsername();
        Date date = new Date();
        return toAjax(cmsFeedbackService.deleteCmsFeedbackByIds(ids, userName, date));
    }


    @Log(title = "在线留言反馈状态标记", businessType = BusinessType.UPDATE)
    @PostMapping("/{id}/status/update")
    public AjaxResult updateStatus(@PathVariable("id") Long id) {

        String userName = SecurityUtils.getUsername();
        Date date = new Date();
        return toAjax(cmsFeedbackService.updateStatus(id, userName, date));
    }
}
